using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
using System.Data;
using DataAccess;

namespace Business
{
    public class CompaniesBusiness
    {
        public DataTable GetCompanies()
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies";
            dt = DA.GetDataTable(sql);
            return dt;
        }

        public int AddCompany(CompaniesEntity companies)
        {
            int i = 0;
            string sql = "INSERT into [dbo].[Companies] VALUES (@CompanyName, @CompanyDescription, @CompanyLocation, @CompanyWebsite)";
            string[] paras = { "@CompanyName", "@CompanyDescription", "@CompanyLocation", "@CompanyWebsite" };
            object[] values = { companies.CompanyName, companies.CompanyDescription, companies.CompanyLocation, companies.CompanyWebsite };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int UpdateCompany(CompaniesEntity companies)
        {
            int i = 0;
            string sql = "UPDATE [dbo].[Companies] SET CompanyName = @CompanyName, CompanyDescription = @CompanyDescription, CompanyLocation = @CompanyLocation, CompanyWebsite = @CompanyWebsite WHERE CompanyID = @CompanyID";
            string[] paras = { "@CompanyName", "@CompanyDescription", "@CompanyLocation", "@CompanyWebsite", "@CompanyID" };
            object[] values = { companies.CompanyName, companies.CompanyDescription, companies.CompanyLocation, companies.CompanyWebsite, companies.CompanyID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int DeleteCompany(int CompanyID)
        {
            int i = 0;
            string sql = "DELETE FROM [dbo].[Companies] WHERE CompanyID = @CompanyID";
            string[] paras = { "@CompanyID" };
            object[] values = { CompanyID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public DataTable GetCompany(int CompanyID)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies WHERE CompanyID = @CompanyID";
            string[] paras = { "@CompanyID" };
            object[] values = { CompanyID };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetCompany(string CompanyName)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies WHERE CompanyName = @CompanyName";
            string[] paras = { "@CompanyName" };
            object[] values = { CompanyName };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetCompany(string CompanyLocation)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies WHERE CompanyLocation = @CompanyLocation";
            string[] paras = { "@CompanyLocation" };
            object[] values = { CompanyLocation };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetCompany(string CompanyWebsite)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies WHERE CompanyWebsite = @CompanyWebsite";
            string[] paras = { "@CompanyWebsite" };
            object[] values = { CompanyWebsite };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetCompany(string CompanyName, string CompanyLocation)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Companies WHERE CompanyName = @CompanyName AND CompanyLocation = @CompanyLocation";
            string[] paras = { "@CompanyName", "@CompanyLocation" };
            object[] values = { CompanyName, CompanyLocation };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }
    }
}
